var database = require('../../core/database'),
	formidable = require('formidable'),
	util = require('util'),
	gcm = require('node-gcm'),
	config = require('../../config'),
	notif = require('../../core/notifications');
/**
 * Web interface notification related methods, PoC
 */


/*
 * Used by android devices to register themselves
 */
exports.register = function(req, res, next) {
	console.log("Request handler 'register' was called. Param: " + req.body.regId);

	database.storeDeviceID(req.body.regId);

	res.send('ID registered: ' + req.body.regId + '\n\n');

};

/*
 * Used by android devices to unregister themselves
 */
exports.unregister = function(req, res, next) {
	console.log("Request handler 'unregister' was called. Param: " + req.body.regId);

	database.removeDeviceID(req.body.regId);

	res.send('ID unregistered: ' + req.body.regId + '\n\n');

};

/*
 * Notify all android devices, test purpose
 */
exports.notify = function(req, res) {
	notif.notify('demo', 'test', res.end);
};

/*
 * Dummy form for testing purpose
 */
exports.form = function(req, res) {
	console.log("Request handler 'form' was called.");
	var body = '<html>' +
		'<head>' +
		'<meta http-equiv="Content-Type" ' +
		'content="text/html; charset=UTF-8" />' +
		'</head>' +
		'<body>' +
		'<p>Register a device by hand (not recommended):</p>' +
		'<form action="/notifications/register" method="post">' +
		'<input type="text" name="regId">' +
		'<input type="submit" value="Register ID" />' +
		'</form>' +
		'<p>Unregister a device by hand (not recommended):</p>' +
		'<form action="/notifications/unregister" method="post">' +
		'<input type="text" name="regId">' +
		'<input type="submit" value="Unregister ID" />' +
		'</form>' +
		'</body>' +
		'</html>';
	res.send(body);
};

